<template>
    <el-table
            :data="tableData"
            style="width: 90%;margin: auto"
            max-height="500">
        <el-table-column
                fixed
                prop="CouName"
                label="CouName"
                width="200">
        </el-table-column>
        <el-table-column
                prop="SchoolTime"
                label="SchoolTime"
                width="120">
        </el-table-column>
        <el-table-column
                prop="Teacher"
                label="Teacher"
                width="120">
        </el-table-column>
        <el-table-column
                prop="Kind"
                label="Kind"
                width="120">
        </el-table-column>

        <el-table-column
                prop="ChooseNum"
                label="ChooseNum"
                width="100">
        </el-table-column>
        <el-table-column
                prop="LimitNum"
                label="LimitNum"
                width="100">
        </el-table-column>
        <el-table-column
                prop="WillNum"
                label="WillNum"
                width="100">
        </el-table-column>
        <el-table-column
                fixed="right"
                label="操作"
                width="120">
            <template v-slot="scope">
                <el-button
                        @click="addcourse(scope.row.CouNo)"
                        type="text"
                        size="small">
                    添加
                </el-button>
                <!--                scope.$index, tableData-->
            </template>
        </el-table-column>
    </el-table>
</template>

<script>
    import qs from "qs";
    const axios = require('axios');
    export default {
        methods: {
            addcourse(CouNo){
                var row=sessionStorage.getItem("row")
                if(row>=5){
                    this.$message({
                        message: '已选满课程',
                        center: true,
                        type: 'error'
                    });
                }else {
                    let postData = qs.stringify({ CouNo:CouNo,StuNo:'00000001'});
                    axios.post("http://localhost/addcourse.php",postData)
                        .then((res) => {
                            console.log(res.data)
                            if(res.data.respon==true){
                                    this.$message({
                                        message: '添加成功',
                                        center: true,
                                        type: 'success'
                                    });
                                this.$router.go(0);
                                sessionStorage.setItem('row',res.data.row);

                            }
                        }).catch((err) => {
                        console.log(err)
                        alert(err);
                         })
                        }
            }
        },
        data() {
            return {
                tableData: []
            }
        },
        created() {
            axios.get("http://localhost/ischoose.php?stuno=00000001")
                .then((res) => {
                     this.tableData=res.data.data
                    console.log(res.data.data);
                })
                .catch((err) => {
                    console.log(err)
                    alert("err");
                })
        }
    }
</script>